//index.js
//获取应用实例
const app = getApp()
// http://39.97.33.178/api/movieOnInfoList?cityId=10
Page({
  data: {
    movieList:[],
    currentArea:{}
  },
  onShow(){
    //初始化调用
    //获取当前城市
    // this.getLocation();
    var currentArea = app.globalData.currentArea;
    this.setData({currentArea})
    //获取电影列表
    var allMovies = app.globalData.movieList;
    console.log("总电影数据：",allMovies)
    // this.movieOnInfoList(currentArea.id);
    let movieList = allMovies.filter(item=>item.aid==currentArea.id)
    // movieList.map((item)=>{
    //   item.img = item.img.replace("w.h","66.94");
    // })
    this.setData({movieList:[]});
    this.setData({movieList});
  },
  toCity(){
    wx.navigateTo({
      url: '/packageA/pages/city/city',
    })
  },
  toSearch(){
    wx.navigateTo({
      url: '/packageB/pages/search/search',
    })
   },
  toPath(e){
    wx.navigateTo({
      url: '/pages/detailMovie/detailMovie?id='+e.currentTarget.dataset.id,
    })
  },
  onShareAppMessage: function (res){
    return {
      title: '电影之家',
      path: '/pages/index/index'
    }
  },
  // movieOnInfoList(id){
  //   wx.request({
  //     url: 'http://39.97.33.178/api/movieOnInfoList?cityId='+id,
  //     success:(res)=>{
  //       console.log(res)
  //       var movieList = this.data.movieList;
  //       movieList = res.data.data.movieList;
  //       movieList.map((item)=>{
  //         item.img = item.img.replace("w.h","66.94");
  //       })
  //       this.setData({movieList});
  //     }
  //   })
  // },
//  getLocation(){
//   wx.request({
//     url: 'http://www.h5yjy.com/api/getLocation',//获取当前城市
//     success:(res)=>{
//       var currentCity = res.data.data;// {nm:"北京",id:111}
//       // 把值给全局globalcity
//       app.globalData.currentCity=currentCity;
//       // 根据当前城市id,获取当前城市 数据
//       this.movieOnInfoList(currentCity.id)
//       this.setData({currentCity});//更新视图的
//     }
//   })
//  },
})
